package com.windy.common.context;

import com.alibaba.ttl.TransmittableThreadLocal;

/**
 * Created by liyufeng on 2022/5/8
 */
public class ThreadLocalContextHolderStrategy<Context> implements ContextHolderStrategy<Context> {

    private final ThreadLocal contextHolder = new TransmittableThreadLocal();

    @Override
    public void clearContext() {
        contextHolder.remove();
    }

    @Override
    public Context getContext() {
        return (Context) contextHolder.get();
    }

    @Override
    public void setContext(Context context) {
        contextHolder.set(context);
    }
}
